package com.example;

import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 课程服务
 * @author aopmin
 * @since 2025/6/10
 */
@Service
public class CourseSerivce {
    private static Logger logger = LoggerFactory.getLogger(CourseSerivce.class);

    private List<Course> courseList = new ArrayList<>();

    /**
     * mock
     */
    @PostConstruct
    public void init() {
        courseList.addAll(List.of(
                new Course("mcp教程", "mcp教程", "https://www.bilibili.com/video/BV1eK5DzHEWu"),
                new Course("python教程", "python教程", "https://www.bilibili.com/video/BV1FaG1zGEyp/"),
                new Course("dify插件教程", "dify插件教程", "https://www.bilibili.com/video/BV15b56zdESS")
        ));
    }


    /**
     * 定义工具：给大模型返回课程列表
     * @return
     */
    @Tool(name = "aopmin_courses",  description = "get a list course from aopmin")
    public List<Course> getCourseList() {
        return courseList;
    }

    /**
     *  定义工具： 根据标题获取课程
     * @param title
     * @return
     */
    @Tool(name = "aopmin_course",  description = "get a course from aopmin")
    public List<Course> getCourse(String title) {
        return courseList.stream().filter(course -> course.title().contains(title)).toList();

    }
}
// AI模型 -> MCP服务 -> 访问万物